package com.elookinto.blackhat;

import java.io.PrintStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class LinkedIn {

    public static void main(String s[]) throws Exception {

        loginPage();

    }

    //http://groups.wenxuecity.com/groupview.php?gid=1562#discussion
    //http://groups.wenxuecity.com/groupview.php?gid=1502
    //http://groups.wenxuecity.com/groupview.php?gid=1173
    public static void loginPage() throws Exception {
        PrintStream sysout = new PrintStream(System.out, true, "UTF-8");
        final WebClient webClient = new WebClient();
        Set<String> uids = new HashSet<String>();

        HtmlPage page = webClient.getPage("http://www.linkedin.com/home?trk=hb_home");
        HtmlForm hf = (HtmlForm) page.getElementById("login");;
        HtmlInput hi = hf.getInputByName("session_key");
        hi.setValueAttribute("Steve.Gates@elookinto.com");
        hi = hf.getInputByName("session_password");
        hi.setValueAttribute("liliping");
        hi = hf.getInputByName("signin");
        hi.click();


       
        page = hi.click();

        //page = webClient.getPage("http://www.linkedin.com/home");

        /*HtmlForm comf = page.getFormByName("mailbox");
         HtmlInput to = comf.getInputByName("to");
         HtmlInput text = comf.getInputByName("title");
         HtmlTextArea hat = comf.getTextAreaByName("msgbody");*/
        page = webClient.getPage("http://www.linkedin.com/directory/people/a.html");
        List<HtmlAnchor> ha = page.getAnchors();
        for (int i = 0; i < ha.size(); i++) {
            String uri = ha.get(i).getHrefAttribute();
            if (!uri.contains("/directory/people")) {
                continue;
            }
            String name = ha.get(i).asText();
            sysout.println(uri + "..." + name);
        }
        //sysout.println(page.asXml());
        page = webClient.getPage("https://www.linkedin.com/pub/maryshuy-a-a/55/637/502");
        sysout.println(page.asXml());
    }

    

    
}
